package com.chookss.view;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.chookss.R;
import com.chookss.Urls;
import com.chookss.WebCommonActivity;
import com.chookss.home.other.WxBindActivity;
import com.chookss.tools.Utils;

import butterknife.BindView;

public class HomeAdvertDialog extends BaseDialog {
    @BindView(R.id.ivContent)
    ImageView ivContent;
    @BindView(R.id.ivClose)
    ImageView ivClose;
    private Context context;
    private String url;

    public HomeAdvertDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_home_advert;
    }

    @Override
    protected void init(View view) {
        initCenter(0.7f);
        ivClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        ivContent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!Utils.isNull(url)) {
                    Intent intent=null;
                    if(url.contains("indexShare.html#/bind")){
                        intent = new Intent(context, WxBindActivity.class);
                        intent.putExtra("url", Urls.bing_wx);
                        intent.putExtra("title", "我的绑定");
                    }else{
                        intent = new Intent(context, WebCommonActivity.class);
                        intent.putExtra("url", url);
                    }
                    context.startActivity(intent);
                }
                dismiss();
            }
        });
    }

    public HomeAdvertDialog(@NonNull Context context, Bitmap bitmap, String url) {
        super(context);
        this.context = context;
        this.url = url;
        Glide.with(ivContent).load(bitmap).into(ivContent);
    }
}
